/**
 * armor is worn by players to reduce incoming damage often at cost of dodge chance
 * @author paul
 *
 */
public class Armor
{
	private StatCounter hp;
	private  final int damReduce;
	private final int dodgePen;

	/**
	 * 
	 * @param damReduce - how much damage is reduce by
	 * @param dodgePen - how much dodge chance is reduced by
	 */
	public Armor(int damReduce, int dodgePen)
	{
		this.damReduce = damReduce;
		this.dodgePen = dodgePen;
		this.hp = new StatCounter(100);
	}
	
	/**
	 * 
	 * @param damReduce - how much damage is reduce by
	 * @param dodgePen - how much dodge chance is reduced by
	 * @param hp - hp or the armor
	 */
	public Armor(int damReduce, int dodgePen, int hp)
	{
		this.damReduce = damReduce;
		this.dodgePen = dodgePen;
		this.hp = new StatCounter(hp);
	}
	/**
	 * returns the dodgePen
	 * @return
	 */
	public int getDodgePen()
	{
		return this.dodgePen;
	}
	
	/**
	 * returns the HP object of armor
	 * @return
	 */
	public StatCounter getHP()
	{
		return this.hp;
	}
	/**
	 * handles damage reduction and returns the result
	 * @param x
	 * @return
	 */
	public int damReduce(int x)
	{
		if( hp.getCurrent() >= this.damReduce)
		{
			if (x >= this.damReduce)
			{
				hp.decrease(damReduce);
				return x - this.damReduce;
			}
			else if (x < this.damReduce);
			{
				hp.decrease(x);
				return 0;
			}
		}
		else if (hp.getCurrent() < this.damReduce)
		{
			if (hp.getCurrent() >= x)
			{
				hp.decrease(x);
				return 0;
			}
			else if (hp.getCurrent() < x)
			{
				int y = x - hp.current;
				hp.setCurrent(0);
				return y;
			}
		}
		return 0;
	}
	
	public String toString()
	{
		return "-" + this.damReduce + " (-" + this.dodgePen +") " + this.hp;
	}
}
